﻿using System;
class FindElBinary
{
    static void Main()
    {
        int lenght;
        int element = 0;
        Console.Write("please enter the lenght of array: ");
        while (true)
        {
            try
            {
                lenght = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter lenght:");
            }
        }
        int[] theArray;
        theArray = new int[lenght];
        for (int i = 0; i < lenght; i++)
        {
            Console.Write("Please enter the {0} element of array: ", i);
            while (true)
            {
                try
                {
                    theArray[i] = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("Please re-enter element:");
                }
            }
        }
        Console.Write("please enter element: ");
        while (true)
        {
            try
            {
                element = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter lenght:");
            }
        }
        Array.Sort(theArray);
        int index = Array.BinarySearch(theArray, element);
        if (index < 0)
        {
            Console.WriteLine("The element {0} is not found", element);
        }
        else
        {
            Console.WriteLine("The element {0} is at position [{1}]", element, index);
        }
        Console.ReadLine();
    }
}

